# coding = UTF-8
# @Time : 2021/11/21 20:22
# @Author : PP_YY
# @File : testsqlite.py
# @Version : 0.1
import sqlite3


if __name__ == "__main__":
    connect = sqlite3.connect("/home/Codes/python/潘猪的爬虫小学习_P/test/test.db") # 默认建在终端所在路径下(打开或创建一个数据库)


    print("打开数据库成功")
    cursor = connect.cursor()# 获取游标，和之前做过的sql课设的操作是差不多的
    # 使用三点来写的话，能保证内容的格式不变
    sql = '''
    create table company
    (
        id int primary key not null,
        name text not null,
        age int not null,
        address char(50),
        salary real
    )
    '''
    sql1 = '''
    insert into company(id,name,age,address,salary)
    values(1,'zhangsan',32,'chengdu',8000)

    '''
    sql2 = '''
    insert into company(id,name,age,address,salary)
    values(2,'zhangsa',32,'sichuan',1999)

    '''

    select = '''
    select * from company

    '''
    delete = '''
    delete from company
    where id = 1
    '''


    # cursor.execute(sql1)
    # cursor.execute(sql2)
    cursor.execute(delete)
    data = cursor.execute(select)
    for item in data:
        print(item)


    # cursor.execute(sql) # 数据库操作
    connect.commit() # 提交数据库操作
    connect.close() # 关闭数据库链接

    # 菜鸟教程可以查询文档


    # print("成功建表")
    print("成功插入")